//
//  RGMessageListCell.m
//  RedGrass
//
//  Created by wukong on 2018/11/25.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "RGMessageListCell.h"
#import "RGMessageContactModel.h"
#import "NSDate+Extension.h"
@interface RGMessageListCell()

@property (strong, nonatomic) UIImageView *userIcon;
@property (strong, nonatomic) UILabel *messageLabel;
@property (strong, nonatomic) UILabel *messageDetailLabel;
@property (strong, nonatomic) UILabel *dateLabel;



@end

@implementation RGMessageListCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.contentView.backgroundColor = [UIColor blackColor];
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        [self initUI];
        [self addMasonry];
    }
    return self;
}

- (void)setModel:(RGMessageContactModel *)model {
    [_userIcon setImageWithURL:[NSURL URLWithString:model.image] placeholder:IMAGE_NAMED(@"头像1")];
    _messageLabel.text = model.nickname;
    _messageDetailLabel.text = model.subModel.content;
    _dateLabel.text = [NSDate changeFormatWithDateString:model.subModel.sendTime];
}

-(void) initUI{
    [self.contentView addSubview:self.userIcon];
    [self.contentView addSubview:self.messageLabel];
    [self.contentView addSubview:self.messageDetailLabel];
    [self.contentView addSubview:self.dateLabel];
}

-(void) addMasonry{
    [_userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 50));
        make.left.mas_equalTo(self.contentView).mas_offset(15);
        make.centerY.mas_equalTo(self.contentView).mas_offset(0);
    }];
    
    [_messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.userIcon.mas_right).mas_offset(10);
        make.top.mas_equalTo(self.userIcon.mas_top).mas_offset(5);
    }];
    
    [_messageDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.userIcon.mas_right).mas_offset(10);
        make.bottom.mas_equalTo(self.userIcon.mas_bottom).mas_offset(-5);
    }];
    
    [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.userIcon.mas_top).mas_offset(7);
        make.right.mas_equalTo(self.contentView).mas_offset(-15);
    }];
}


#pragma mark - getter
-(UIImageView *)userIcon{
    if(!_userIcon){
        _userIcon = [[UIImageView alloc]init];
        _userIcon.image = IMAGE_NAMED(@"头像1");
        ViewRadius(_userIcon, 25);
    }
    return _userIcon;
}

-(UILabel *)messageLabel{
    if(!_messageLabel){
        _messageLabel = [[UILabel alloc]init];
        _messageLabel.textColor = [UIColor whiteColor];
        _messageLabel.font = FONT(customFontName, 15);
        _messageLabel.text = @"陌生人消息";
    }
    return _messageLabel;
}

-(UILabel *)messageDetailLabel{
    if(!_messageDetailLabel){
        _messageDetailLabel = [[UILabel alloc]init];
        _messageDetailLabel.textColor = CFontColor3;
        _messageDetailLabel.font = FONT(customFontName, 13);
        _messageDetailLabel.text = @"消息内容";
    }
    return _messageDetailLabel;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [[UILabel alloc]init];
        _dateLabel.textColor = CFontColor3;
        _dateLabel.text = @"10-09";
        _dateLabel.font = FONT(customFontName, 12);
    }
    return _dateLabel;
}

@end
